001    /**
002     * Created by IntelliJ IDEA.
003     * User: Wei Wang
004     * Date: Feb 26, 2003
005     * Time: 7:57:04 PM
006     */
007    
008    package EVolve.util.painters.placements;
009    
010    import EVolve.util.painters.shapes.Shape;
011    import EVolve.visualization.AutoImage;
012    import EVolve.exceptions.NoDataPlotException;
013    
014    import java.awt.*;
015    
016    public class RectPlacement extends Placement{
017    
018        public RectPlacement(int shapeSize) {
019            super();
020            this.shapeSize = shapeSize;
021        }
022    
023        public String getName() {
024            return "Rectangle Placement";
025        }
026    
027        public Rectangle initialPlacement(AutoImage image) throws NoDataPlotException{
028            int totalShapes = parties[0].size() + parties[1].size();
029            int startX, startY, delta;
030            int objectInLines = 0;
031    
032            if (parties[0] == parties[1]) totalShapes /= 2;
033    
034            startX = startY = INDENT;
035            delta = 30;
036    
037            int i = 0,producerSize = parties[0].size();
038    
039            if (producerSize == 0) throw new NoDataPlotException();
040    
041            while (i<totalShapes) {
042                for (int j=0; j<parties[i/producerSize].size(); j++) {
043                    Shape object = (Shape)parties[i/producerSize].get(new Integer(j));
044                    object.move(startX+j*delta-shapeSize/2,startY-shapeSize/2);
045                }
046                if (objectInLines < parties[i/producerSize].size())
047                    objectInLines = parties[i/producerSize].size();
048                i += parties[i/producerSize].size();
049                startY = INDENT + 350;
050            }
051            Rectangle bounds = new Rectangle();
052            bounds.height = 2*(INDENT + shapeSize)+350;
053            bounds.width = shapeSize + delta * (objectInLines - 1) + INDENT*2;
054    
055            image.setImageWidth(bounds.width, bounds.height);
056            return bounds;
057        }
058    }